var loading = false; //状态标记

var loadTabContent = function (self, page, build = false) {
    if (loading)
        return;

    var loader = $(self).find(".weui-loadmore");

    $.ajax({
        type: "GET",
        url: $(self).data('href'),
        dataType: "html",
        data: {name: "上海", page: page},
        beforeSend: function () {
            //请求前的处理
            loader.show();
            loading = true;
        },
        success: function (json) {
            if (build) {
                $(self).find(".weui-tab-content").html(json);
            } else {
                $(self).find(".weui-tab-content").append(json);
            }
            loading = false;
        },
        error: function (e) {
            alert("失败");
        },
        complete: function () {
            //请求完成的处理
            loader.hide();
            loading = false;
        }
    });
};

$(".weui-navbar__item").each(function () {
    if ($(this).hasClass('weui-bar__item--on')) {
        var self = $(this).attr('href');
        console.log(self)
        loadTabContent($(self), $(this).data('id'), true);
    }
});

$('.weui-navbar__item').on('click', function () {
    //e.preventDefault();
    var self = $(this).attr('href');
    console.log(self)
    loadTabContent($(self), $(this).data('id'), true);
});

$(".infinite").infinite().on("infinite", function () {
    var self = this;
    loadTabContent(self, 1);
});